from functools import wraps
from flask import request
from src.utils import api_util
import datetime


def token_verify(f):
    @wraps(f)
    def verify(*args, **kwargs):
        token = request.headers.get("auth-token")
        print("auth-token:", token)
        if not token:
            return api_util.fail("校验不通过", "Token is missing", code = "10000")

        try:
            # secret_key = setting.get_config("key.secret_key")
            # data = jwt.decode(token, secret_key, algorithms=["HS256"])
            # current_user = query_user(data.get("user_name"))
            # current_user["uuid"] = data.get("uuid")
            # current_user["token"] = token
            current_user = {
                    "id": 1,
                    "user_name": "ces1",
                    "nick_name": "ceshi",
                    "pwd_encode": "$2b$12$Ah3uEvPSO4QXm2VoNY78FOjfWdY3a",
                    "pwd_salt": "$2b$12$Ah3uEvPS",
                    "phone_num": "19811111111",
                    "verification": "278285",
                    "remark": None,
                    "role_id": 1,
                    "team_id": 1,
                    "team_admin": 0,
                    "icon_url": None,
                    "state": 1,
                    "usage_space": 5.901070153340697,
                    "remain_space": 994.0989298466593,
                    "created_at": datetime.datetime(2025, 3, 5, 1, 43, 48),
                    "update_at": datetime.datetime(2025, 6, 13, 20, 51, 58),
                    "expire_at": datetime.datetime(2030, 6, 3, 0, 0),
                    "package_id": "PRC20250604000007",
                    "uuid": "cda75426b5124d1e",
                    "token": "xIiwidXNlcl9pZCI6MSwiZXhwIjoxNzUxNTQxNjU5LCJ1dWlkIjoiY2RhNzU0MjZiNTEyNGQxZSJ9.miVX1810hlqpyThFFbt1EqX-t9hptoiqi8RmaCOH58c"
                }
        except Exception:
            return api_util.fail("校验不通过", "Token is missing", code = "10000")

        return f(current_user, *args, **kwargs)

    return verify
